﻿(function($) {
	$.editor = {

		defaultOptions: {
			path : "",
			width : 550,
			height : 250,
			colors : getColors(),
			fonts : "宋体,雅黑,Arial,黑体,Comic Sans MS,Courier New,Georgia,Verdana",
			sizes : "1,2,3,4,5,6,7",
			styles : [["普通分段", "<p>"], ["标题1", "<h1>"], ["标题2", "<h2>"], ["标题3", "<h3>"],  ["标题4","<h4>"],  ["标题5","<h5>"], ["标题6","<h6>"]],
			docCode : getDocs()
		},
		defaultButtons: [
			{name:"bold", title:"加粗"},
			{name:"italic", title:"斜体"},
			{name:"underline", title:"下划线"},
			{name:"strikethrough", title:"删除线"},
			{name:"subscript", title:"下标"},
			{name:"superscript", title:"上标"},
			{name:"|"},
			{name:"font", title:"字体", command:"fontname", popupName:"font"},
			{name:"size", title:"字体大小", command:"fontsize", popupName:"size"},
			{name:"style", title:"标题样式", command:"formatblock", popupName:"style"},
			{name:"color", title:"文字颜色", command:"forecolor", popupName:"color"},
			{name:"highlight", title:"背景色", command:"hilitecolor", popupName:"color"},
			{name:"removeformat", title:"清除格式"},
			{name:"|"},
			{name:"bullets", title:"符合列表", command:"insertunorderedlist"},
			{name:"numbering", title:"数字列表", command:"insertorderedlist"},
			{name:"outdent", title:"减少缩进"},
			{name:"indent", title:"增加缩进"},
			{name:"|"},
			{name:"alignleft", title:"左对齐", command:"justifyleft"},
			{name:"center", title:"居中对齐", command:"justifycenter"},
			{name:"alignright", title:"右对齐", command:"justifyright"},
			{name:"justify", title:"两端对齐", command:"justifyfull"},
			{name:"|"},
			{name:"rule", title:"插入横杆", command:"inserthorizontalrule"},
			{name:"image", title:"插入图片", command:"insertimage", popupName:"url"},
			{name:"link", title:"设置链接", command:"createlink", popupName:"url"},
			{name:"unlink", title:"移除链接"},
			
			
			//table plugin
			{name:"table", title:"插入表格", command:"inserthtml", popupName:"table", popupClass:"editorPrompt",
				popupContent: '行：<input type="text" value="3" size="6" /> 列：<input type="text" value="3" size="6" /> <input type="button" value="确定">',
				buttonClick: function (e, data) {
					$(data.popup).children(":button").unbind(CLICK).bind(CLICK, function(e) {
						var editor = data.editor;
						var $text = $(data.popup).find(":text"),
						cols = parseInt($text[0].value),
						rows = parseInt($text[1].value);
						var html;
						if (cols > 0 && rows > 0) {
							html = '<table cellpadding="2" cellspacing="2" border="1">';
							for (var j = 0; j < rows; j++) {
								html += "<tr>";
								for (var i = 0; i < cols; i++)
									html += "<td>[" + (j + 1) + DOT + (i + 1) + "]</td>";
								html += "</tr>";
							}
							html += "</table>";
						}
						if (html) {
							editor.execCommand(data.command, html, data.button);
						}
						$text.val(3);
						editor.hidePopups();
						editor.focus();
					});
				}
			},
			
			
			//google map plugin
			{name:"map", title:"插入地图", command:"insertimage", popupName:"map", popupClass:"editorPrompt",
				popupContent : '<iframe frameborder="0" src="javascript:void(0)"></iframe>',
				buttonClick : function (e, data) {
					$iframe = $(data.popup).find("iframe").data("data", data);
					var path = data.editor.options.path;
					var gurl = path + "googlemap.htm";
					if ($iframe.attr("src") != gurl) {
						$iframe.attr("src", gurl).load(function(){
							var obj = $iframe.contents().find("body").children();
							$iframe.width(obj.outerWidth()).height(obj.outerHeight());
							$iframe[0].contentWindow.callback = function(url) {
								var data = $iframe.data("data");
								var editor = data.editor;
								execCommand(editor, data.command, url, data.button);
								editor.hidePopups();
								editor.focus();
							};
						});
					}
				}
			},
			
			
			{name:"|"},
			{name:"cut", title:"剪切"},
			{name:"copy", title:"拷贝"},
			{name:"paste", title:"粘贴"},
			{name:"pastetext", title:"粘贴到文本", command:"inserthtml", popupName:"pastetext", popupClass:"editorPrompt",
				popupContent:'粘贴内容：<br /><textarea cols="40" rows="3"></textarea><br /><input type="button" value="确定" />'
			},
			{name:"|"},
			{name:"print", title:"打印"},
			{name:"html", title:"显示HTML源码"}
		]
		
	};
  
	$.fn.editor = function(options) {
		var $result = $([]);
		this.each(function(idx, elem) {
			if (elem.tagName.toUpperCase() == "TEXTAREA") {
				var data = $(elem).data(EDITOR);
				if (!data) data = new editor(elem, options);
					$result = $result.add(data);
			}
		});
		return $result;
	};
    

	var
	BACKGROUND_COLOR = "backgroundColor",
	DOT              = ".",
	BUTTON           = "button",
	BUTTON_NAME      = "buttonName",
	CHANGE           = "change",
	EDITOR           = "editor",
	CLICK            = "click",
	DISABLED         = "disabled",
	DIV_TAG          = "<div>",
	UNSELECTABLE     = "unselectable",
	MAIN_CLASS       = "editorMain",
	TOOLBAR_CLASS    = "editorToolbar",
	BARBG_CLASS      = "editorBarbg",
	GROUP_CLASS      = "editorGroup",
	BUTTON_CLASS     = "editorButton",
	DISABLED_CLASS   = "editorDisabled",
	DIVIDER_CLASS    = "editorDivider",
	POPUP_CLASS      = "editorPopup",
	LIST_CLASS       = "editorList",
	COLOR_CLASS      = "editorColor",
	PROMPT_CLASS     = "editorPrompt",
	MSG_CLASS        = "editorMsg",
	ie = $.browser.msie,
	buttons = {},
	popups = {},
	documentClickAssigned,
	editor = function(area, options) {
		var editor = this;
		options = $.extend({}, $.editor.defaultOptions, options);
		var $area = $(area).hide().data(EDITOR, editor);
		options.width = $area.outerWidth() - 2;
		options.height = $area.outerHeight() - 2;
		
		// Create the main container and append the textarea
		var $main = $(DIV_TAG).addClass(MAIN_CLASS).width(options.width).height(options.height).insertBefore($area).append($area);
		var $toolbar = $(DIV_TAG).addClass(TOOLBAR_CLASS).prependTo($main);
		var $group = $(DIV_TAG).addClass(GROUP_CLASS).appendTo($toolbar);
		
		var bts = $.editor.defaultButtons;
		var len = bts.length;
		for (var i = 0; i < len; i ++) {
			var button = bts[i];
			var buttonName = button.name;
			if (!buttonName) {
				break;
			}
			button.command = button.command || buttonName;
			buttons[buttonName] = button;
			
			if (buttonName == "|") {
				$(DIV_TAG).addClass(DIVIDER_CLASS).appendTo($group);
				//new group
				$group = $(DIV_TAG).addClass(GROUP_CLASS).appendTo($toolbar);
			} else {
				var $buttonDiv = $("<a>").attr("href","javascript:void(0)").data(BUTTON_NAME, buttonName)
				.addClass(BUTTON_CLASS + " " + buttonName + "Skin")
				.attr("title", button.title)
				.bind(CLICK, $.proxy(buttonClick, editor))
				.appendTo($group);
				
				if (ie) {
					$buttonDiv.attr(UNSELECTABLE, "on");
				}
				if (button.popupName) {
					createPopup(button, options);
				}
			}
		}
		
		editor.$main = $main;
		editor.$toolbar = $toolbar;
		editor.$area = $area;
		editor.options = options;
		if (!documentClickAssigned) {
			$(document).click(function(e) {
				var $target = $(e.target);
				if (!$target.add($target.parents()).is(DOT + PROMPT_CLASS))
					hidePopups();
			});
			documentClickAssigned = true;
		}
		refresh(editor);
	};

	var fn = editor.prototype,
	methods = [
		["clear", clear],
		["disable", disable],
		["execCommand", execCommand],
		["focus", focus],
		["hidePopups", hidePopups],
		["htmlMode", htmlMode, true],
		["refresh", refresh],
		["select", select],
		["selectedText", selectedText, true],
		["showMessage", showMessage],
		["updateFrame", updateFrame],
		["updateTextArea", updateTextArea]
	];
	$.each(methods, function(idx, method) {
		fn[method[0]] = function() {
			var editor = this, args = [editor];
			// using each here would cast booleans into objects!
			for(var x = 0; x < arguments.length; x++) {
				args.push(arguments[x]);
			}
			var result = method[1].apply(editor, args);
			if (method[2]) return result;
			return editor;
		};
	});

	function buttonClick(e) {
		
		var editor = this;
		var buttonDiv = e.target;
		var buttonName = $(buttonDiv).data(BUTTON_NAME);
		var button = buttons[buttonName];
		var popupName = button.popupName;
		var popup = popups[popupName];
		
		// Check if disabled
		if (editor.disabled || $(buttonDiv).attr(DISABLED) == DISABLED) {
			return;
		}
		// Fire the buttonClick event
		var data = {
			editor: editor,
			button: buttonDiv,
			buttonName: buttonName,
			popup: popup,
			popupName: popupName,
			command: button.command,
			value: null
		};
		
		if (button.buttonClick && button.buttonClick(e, data) === false) {
			return false;
		}
		
		if (buttonName == "html") {
			if (htmlMode(editor)) {
				updateFrame(editor);
				editor.$area.hide();
				editor.$frame.show();
			} else {
				updateTextArea(editor);
				editor.$frame.hide();
				editor.$area.show();
			}
			setTimeout(function() {
				refreshButtons(editor);
			}, 100);
		
		} else if (!htmlMode(editor)) {
			
			
			
			// Handle popups
			if (popupName) {
				var $popup = $(popup);
			
				// URL
				if (popupName == "url") {
			
					if (buttonName == "link" && selectedText(editor) == "") {
						showMessage(editor, "请先选择一段要设置链接的文字", buttonDiv);
						return false;
					}
					
					$popup.children(":button").unbind(CLICK).bind(CLICK, function() {
						var $text = $popup.find(":text");
						var url = $.trim($text.val());
						if (url != "") {
							execCommand(editor, data.command, url, data.button);
						}
						$text.val("http://");
						hidePopups();
						focus(editor);
					});
		
				} else if (popupName == "pastetext") {
					$popup.children(":button").unbind(CLICK).bind(CLICK, function() {
						var $textarea = $popup.find("textarea");
						var text = $textarea.val().replace(/\n/g, "<br />");
						if (text != "") {
							execCommand(editor, data.command, text, data.button);
						}
						$textarea.val("");
						hidePopups();
						focus(editor);
					});
				}
				if (buttonDiv !== $(popup).data(BUTTON)) {
					showPopup(editor, popup, buttonDiv);
					return false;
				}
				// propaginate to documnt click
				return;
			
			} else if (buttonName == "print") {
				editor.$frame[0].contentWindow.print();
			} else if (!execCommand(editor, data.command, data.value, buttonDiv)) {
				return false;
			}
			
		
		}
		focus(editor);
	}
	// popupClick - click event handler for popup items
	function popupClick(e) {
	
		var editor = this;
		var popup = e.data.popup;
		var $popup = $(popup);
		var target = e.target;
		
		// Check for message and prompt popups
		if (popup === popups.msg || $popup.hasClass(PROMPT_CLASS)) {
			return;
		}
		// Get the button info
		var buttonDiv = $popup.data(BUTTON);
		var buttonName = $(buttonDiv).data(BUTTON_NAME);
		var button = buttons[buttonName];
		var command = button.command;
		var value = null;
		
		// Get the command value
		if (buttonName == "font") {
			value = target.style.fontFamily.replace(/"/g, "");
		} else if (buttonName == "size") {
			if (target.tagName.toUpperCase() == "DIV") {
				target = target.children[0];
			}
			value = target.innerHTML;
		} else if (buttonName == "style") {
			value = "<" + target.tagName + ">";
		} else if (buttonName == "color") {
			value = hex(target.style.backgroundColor);
		} else if (buttonName == "highlight") {
			value = hex(target.style.backgroundColor);
			if (ie) {
				command = 'backcolor';
			}
		}
		
		// Fire the popupClick event
		var data = {
			editor: editor,
			button: buttonDiv,
			buttonName: buttonName,
			popup: popup,
			popupName: button.popupName,
			command: command,
			value: value
		};
		
		if (button.popupClick && button.popupClick(e, data) === false)
			return;
		
		// Execute the command
		if (data.command && !execCommand(editor, data.command, data.value, buttonDiv))
			return false;
		
		// Hide the popup and focus the editor
		hidePopups();
		focus(editor);
	
	}

	function clear(editor) {
		editor.$area.val("");
		updateFrame(editor);
	}

	function createPopup(button, options) {
		var popupName = button.popupName;
		if (!popupName) {
			return;
		}
		if (popups[popupName]) return popups[popupName];

		var popupClass = button.popupClass;
		var popupContent = button.popupContent;
		
		var $popup = $(DIV_TAG).hide().addClass(POPUP_CLASS).appendTo("body");
		
		if (popupContent) {
			$popup.html(popupContent);
		} else if (popupName == "color") {
			$.each(options.colors, function(idx, color) {
				$(DIV_TAG).appendTo($popup).css(BACKGROUND_COLOR, color).attr("title", color);;
			});
			popupClass = COLOR_CLASS;
		} else if (popupName == "font") {
			$.each(options.fonts.split(","), function(idx, font) {
				$(DIV_TAG).appendTo($popup).css("fontFamily", font).html(font);
			});
		} else if (popupName == "size") {
			$.each(options.sizes.split(","), function(idx, size) {
				$(DIV_TAG).appendTo($popup).html("<font size=" + size + ">" + size + "</font>");
			});
		} else if (popupName == "style") {
			$.each(options.styles, function(idx, style) {
				$(DIV_TAG).appendTo($popup).html(style[1] + style[0] + style[1].replace("<", "</"));
			});
		} else if (popupName == "url") {
			$popup.html('输入地址：<br /><input type="text" value="http://" size="35" onfocus="this.select()" /><br /><input type="button" value="确定" />');
			popupClass = PROMPT_CLASS;
		}
		
		if (!popupClass && !popupContent) {
			popupClass = LIST_CLASS;
		}
		$popup.addClass(popupClass);
		if (ie) {
			$popup.attr(UNSELECTABLE, "on").find("div,font,p,h1,h2,h3,h4,h5,h6").attr(UNSELECTABLE, "on");
		}
		popups[popupName] = $popup[0];
		return $popup[0];
	}

	function disable(editor, disabled) {
		if (disabled) {
			editor.$area.attr(DISABLED, DISABLED);
			editor.disabled = true;
		} else {
			editor.$area.removeAttr(DISABLED);
			delete editor.disabled;
		}
		try {
			if (ie) editor.doc.body.contentEditable = !disabled;
			else editor.doc.designMode = !disabled ? "on" : "off";
		} catch (err) {}
		refreshButtons(editor);
	}

	//executes a designMode command
	function execCommand(editor, command, value, button) {
	
		// Restore the current ie selection
		if (ie && editor.range)
			editor.range.select();
		
		// Execute the command and check for error
		var success = true, description;
		if (command.toLowerCase() == "inserthtml" && ie) {
		
			try {
				editor.doc.selection.createRange().pasteHTML(value);  
			} catch (e) {
				$(editor.doc.body).append(value);
			}
		
		} else {
			try { 
				success = editor.doc.execCommand(command, 0, value || null); 
			} catch (err) { 
				description = err.description; 
				success = false; 
			}
			if (!success) {
				if ("cutcopypaste".indexOf(command) > -1)
					showMessage(editor, "错误命令：" + command, button);
				else
					showMessage(editor, (description ? description : "错误命令：" + command), button);
			}
		}
		updateTextArea(editor);
		refreshButtons(editor);
		return success;
	}

	// Returns the hex value for the passed in string.
	//   hex("rgb(255, 0, 0)"); // #FF0000
	//   hex("#FF0000"); // #FF0000
	//   hex("#F00"); // #FF0000
	function hex(c) {
		var m = /rgba?\((\d+), (\d+), (\d+)/.exec(c),
		s = c.split("");
		return m ? "#" + ( m[1] << 16 | m[2] << 8 | m[3] ).toString(16) : c.length == 7 ? c : "#" + s[1] + s[1] + s[2] + s[2] + s[3] + s[3];
	}

	// focus - sets focus to either the textarea or iframe
	function focus(editor) {
		setTimeout(function() {
			if (htmlMode(editor)) editor.$area.focus();
			else editor.$frame[0].contentWindow.focus();
		}, 10);
	}
	
	// hidePopups - hides all popups
	function hidePopups() {
		$.each(popups, function(idx, popup) {
			$(popup).hide().unbind(CLICK).removeData(BUTTON);
		});
	}
	
	function getColors() {
		var arr1 = [], arr2 = [];
		for (var i = 0; i <= 0xf; i = i + 3) {
			for (var j = 0; j <= 0xf; j = j + 3) {
				for (var k = 0; k <= 0xf; k = k + 3) {
					var c = "#" + i.toString(16) + j.toString(16) + k.toString(16);
					j < 9 ? arr1.push(c) : arr2.push(c);
				}	
			}
		}
		return arr1.concat(arr2);
	}
	
	function getDocs() {
		var htm = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">';
		htm += '<html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" />';
		htm += '<style type="text/css">html,body{height:100%;}html,body,p,h1,h2,h3,h4,h5,h6{margin:0;padding:0;outline:0;text-align:left;font-size:12px;}</style></head><body></body></html>';
		return htm;
	}
	// htmlMode - returns true if the textarea is showing
	function htmlMode(editor) {
		return editor.$frame.css("display") == "none";
	}

	function refresh(editor) {
		var options = editor.options;
		// Remove the old iframe
		if (editor.$frame) 
			editor.$frame.remove();
		
		// Create a new iframe
		var $frame = $('<iframe frameborder="0" src="javascript:true;"></iframe>');
		//editor.$toolbar.after($frame);
		editor.$main.append($frame);
		// Load the iframe document content
		var doc = $frame[0].contentWindow.document;
		doc.open();
		doc.write(options.docCode);
		doc.close();
		
		$(doc.body).html(editor.$area.val());
		// Define the editor properties
		editor.$frame = $frame;
		editor.doc = doc;
		
		// Switch the iframe into design mode
		disable(editor, editor.disabled);
		
		// Bind the ie specific iframe event handlers
		if (ie) {
			// Save the selection when it changes  
			$(doc).bind("beforedeactivate beforeactivate selectionchange", function(e) {
				if (e.type == "beforedeactivate") editor.skip = true;
				else if (e.type == "beforeactivate") delete editor.skip;
				else if (!editor.skip) editor.range = doc.selection.createRange();
			});
			// Restore the selection when the iframe gains focus
			$frame.focus(function() {
				if (editor.range)
					editor.range.select();
			});
		}
		
		// Bind the iframe document event handlers
		$(doc).click(hidePopups).bind("keyup mouseup", function(e) {
			refreshButtons(editor);
			updateTextArea(editor);
		});
		
		// Wait for the layout to finish
		setTimeout(function() {
			var $toolbar = editor.$toolbar;
			var $group = $toolbar.children("div:last");
			var hgt = $group.offset().top + $group.outerHeight() - $toolbar.offset().top;
			$toolbar.height(hgt);
			//
			var wid = options.width;
			hgt = options.height - hgt;
			$frame.width(wid).height(hgt);
			editor.$area.width(wid).height(hgt);
			//
			refreshButtons(editor);
		}, 10);
	
	}

	//enables or disables buttons based on availability
	function refreshButtons(editor) {
		
		// Loop through each button
		$.each(editor.$toolbar.find(DOT + BUTTON_CLASS), function(idx, elem) {
			
			
			var $elem = $(elem);
			var buttonName = $elem.data(BUTTON_NAME);
			var button = buttons[buttonName];
			if (!button) {
				return;	
			}
			var command = button.command;
			var enabled = true;
			
			// Determine the state
			if (editor.disabled) {
				enabled = false;
			} else if (button.getEnabled) {
				var data = {
					editor: editor,
					button: $elem[0],
					buttonName: button.name,
					popup: popups[button.popupName],
					popupName: button.popupName,
					command: button.command,
					value: null
				};
				enabled = button.getEnabled(data);
				if (typeof enabled == "undefined") {
					enabled = true;
				}
				
			} else if ((htmlMode(editor) && button.name != "html")) {
				enabled = false;
			} else if (command && command != "print" && command != "html") {
				if (ie && command == "hilitecolor") {
					command = "backcolor";
				}
				if (!ie || command != "inserthtml") {
					try {
						enabled = editor.doc.queryCommandEnabled(command);
					} catch (e) {
					}
				}
			}
			
			// Enable or disable the button
			if (enabled) {
				$elem.removeClass(DISABLED_CLASS);
				$elem.removeAttr(DISABLED);
			} else {
				$elem.addClass(DISABLED_CLASS);
				$elem.attr(DISABLED, DISABLED);
			}
		
		});
	}

	// select - selects all the text in either the textarea or iframe
	function select(editor) {
		setTimeout(function() {
			if (htmlMode(editor)) editor.$area.select();
			else execCommand(editor, "selectall");
		}, 10);
	}
	
	// selectedText - returns the current text selection or and empty string
	function selectedText(editor) {
		if (ie) return editor.doc.selection.createRange().text;
		return editor.$frame[0].contentWindow.getSelection();
	}
	
	function showMessage(editor, message, button) {
		alert(message);
	}

	function showPopup(editor, popup, button) {
		var offset, left, top, $popup = $(popup);
		// Determine the popup location
		if (button) {
			var $button = $(button);
			offset = $button.offset();
			left = --offset.left;
			top = offset.top + $button.height();
		} else {
			var $toolbar = editor.$toolbar;
			offset = $toolbar.offset();
			left = Math.floor(($toolbar.width() - $popup.width()) / 2) + offset.left;
			top = offset.top + $toolbar.height() - 2;
		}
		// Position and show the popup
		hidePopups();
		$popup.css({left: left, top: top}).show();
		// Assign the popup button and click event handler
		if (button) {
			$popup.data(BUTTON, button);
			$popup.bind(CLICK, {popup: popup}, $.proxy(popupClick, editor));
		}
		// Focus the first input element if any
		setTimeout(function() {
			$popup.find(":text,textarea:first").focus().select();
		}, 100);
	}

	function updateFrame(editor) {
		var val = editor.$area.val();
		var $body = $(editor.doc.body);
		if (val != $body.html()) {
			val = val.replace(/<(?=\/?script)/ig, "&lt;");
			try {
				$body.html(val);
			} catch(e) {
				alert("插入的html格式错误");
			}
		}
	}
	
	function updateTextArea(editor) {
		var html = $(editor.doc.body).html();
		if (ie) {
			html = tagFormat(html);
		}
		var $area = editor.$area;
		if (html != $area.val()) {
			$area.val(html).triggerHandler(CHANGE);
		}
	}
	
	function tagFormat(str) {
		str = ieInnerHTML(str);
		return str;	
	}
	
	
	function ieInnerHTML(zz) { 
		var z = zz.match(/<\/?\w+((\s+\w+(\s*=\s*(?:".*?"|'.*?'|[^'">\s]+))?)+\s*|\s*)\/?>/g);
		if (z){
			var i = 0;
			var zlen = z.length;
			while(i < zlen){ 
				//替换标签大写为小写
				var zSaved = z[i];
				z[i] = z[i].replace(/(<?\w+)|(<\/?\w+)\s/, function(a){
					return a.toLowerCase();
				}); 
				//添加属性双引号
				var y = z[i].match(/\=[a-zA-Z\.\:\[\]_\(\)\&\$\%#\@\!0-9]+[?\s+|?>]/g);
				if (y) {
					var j = 0;
					var ylen = y.length;
					while(j < ylen){ 
						z[i] = z[i].replace(y[j], y[j].replace(/(\=)([a-zA-Z\.\:\[\]_\(\)\&\$\%#\@\!0-9]+)?([\s+|?>])/g, function(){ 
							var args = Array.prototype.slice.call(arguments); 
							var str = args[1] + '"' + args[2] + '"' + args[3];
							return str; 
						})); 
						j++; 
					} 
				} 
				zz = zz.replace(zSaved, z[i]); 
				i ++;
			} 
		} 
		return zz; 
	} 

	

})(jQuery);
